import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_train_exam_appro.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
/// 审核不合格备注
class TrainExamApproNoPassWidget extends StatefulWidget {
  final int id;

  const TrainExamApproNoPassWidget({Key key, this.id}) : super(key: key);

  @override
  _TrainExamApproNoPassWidgetState createState() =>
      _TrainExamApproNoPassWidgetState();
}

class _TrainExamApproNoPassWidgetState
    extends State<TrainExamApproNoPassWidget> {
  TextEditingController _editingController = TextEditingController();

  FocusNode _focusNode = FocusNode();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("不合格原因"),
      ),
      backgroundColor: Colors.white,

      ///填充布局
      body: Container(
          width: double.infinity,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.all(12),
                  child: TextField(
                    controller: _editingController,
                    maxLength: 200,
                    maxLines: 10,
                    focusNode: _focusNode,
                    style: TextStyle(),
                    decoration: InputDecoration(
                        hintText: "请输入不合格原因(最多200字)",
                        border: OutlineInputBorder()),
                  ),
                ),
                Align(
                  child: Container(
                    width: 100,
                    margin: EdgeInsets.only(right: 12),
                    child: ElevatedButton(
                      onPressed: () {
                        String text = _editingController.text;
                        if (text.length == 0) {
                          ToastUtils.showToast("请输入不合格原因");
                          return;
                        }
                        _commitTrainAppro(text);
                      },
                      child: Text("提交"),
                    ),
                  ),
                  alignment: Alignment.centerRight,
                ),
              ],
            ),
          )),
    );
  }

  Future<BeanTrainExamAppro> _commitTrainAppro(String approRemark) async {
    _focusNode.unfocus();
    Map<String, dynamic> map = new Map();
    map["id"] = widget.id;
    map["approStatues"] = 2;
    map["approRemark"] = approRemark;

    ResponseInfo statisRresponseInfo = await DioUtils.instance
        .postRequest(url: HttpHelper.trainExamApproUpdateUrl, jsonMap: map);
    if (statisRresponseInfo.success) {
      BeanTrainExamAppro beanTrainExamAppro =
          BeanTrainExamAppro.fromMap(statisRresponseInfo.data);
      NavigatorUtils.pop(context, parameters: beanTrainExamAppro);
      return null;
    } else {
      ToastUtils.showToast(statisRresponseInfo.message);
      return null;
    }
  }
}
